public class RequestPartMethodArgumentResolver extends AbstractMessageConverterMethodArgumentResolver
@RequestPart
MultipartFile
in conjunction with Spring's MultipartResolver
abstraction
javax.servlet.http.Part
in conjunction with Servlet 3.0 multipart requests
When a parameter is annotated with @RequestPart
, the content of the part is
passed through an HttpMessageConverter
to resolve the method argument with the
'Content-Type' of the request part in mind. This is analogous to what @RequestBody
does to resolve an argument based on the content of a regular request.
When a parameter is not annotated or the name of the part is not specified, it is derived from the name of the method argument.
Automatic validation may be applied if the argument is annotated with
@javax.validation.Valid
. In case of validation failure, a
MethodArgumentNotValidException
is raised and a 400 response status
code returned if DefaultHandlerExceptionResolver
is configured.
allSupportedMediaTypes, logger, messageConverters
Constructor and Description |
---|
RequestPartMethodArgumentResolver(java.util.List<HttpMessageConverter<?>> messageConverters) |
Modifier and Type | Method and Description |
---|---|
private static void |
assertIsMultipartRequest(HttpServletRequest request) |
private java.lang.String |
getPartName(MethodParameter methodParam) |
private boolean |
isBindExceptionRequired(WebDataBinder binder,
MethodParameter methodParam)
Whether to raise a fatal bind exception on validation errors.
|
private boolean |
isMultipartFileCollection(MethodParameter methodParam) |
java.lang.Object |
resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest request,
WebDataBinderFactory binderFactory)
Resolves a method parameter into an argument value from a given request.
|
boolean |
supportsParameter(MethodParameter parameter)
Supports the following:
annotated with
@RequestPart
of type MultipartFile unless annotated with @RequestParam
of type javax.servlet.http.Part unless annotated with @RequestParam
|
private void |
validate(WebDataBinder binder,
MethodParameter methodParam)
Validate the request part if applicable.
|
createInputMessage, readWithMessageConverters, readWithMessageConverters
public RequestPartMethodArgumentResolver(java.util.List<HttpMessageConverter<?>> messageConverters)
public boolean supportsParameter(MethodParameter parameter)
@RequestPart
MultipartFile
unless annotated with @RequestParam
javax.servlet.http.Part
unless annotated with @RequestParam
parameter
- the method parameter to checktrue
if this resolver supports the supplied parameter;
false
otherwisepublic java.lang.Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory) throws java.lang.Exception
HandlerMethodArgumentResolver
ModelAndViewContainer
provides access to the model for the
request. A WebDataBinderFactory
provides a way to create
a WebDataBinder
instance when needed for data binding and
type conversion purposes.parameter
- the method parameter to resolve. This parameter must
have previously been passed to
HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
and it must have returned true
mavContainer
- the ModelAndViewContainer for the current requestrequest
- the current requestbinderFactory
- a factory for creating WebDataBinder
instancesnull
.java.lang.Exception
- in case of errors with the preparation of argument valuesprivate static void assertIsMultipartRequest(HttpServletRequest request)
private java.lang.String getPartName(MethodParameter methodParam)
private boolean isMultipartFileCollection(MethodParameter methodParam)
private void validate(WebDataBinder binder, MethodParameter methodParam) throws MethodArgumentNotValidException
The default implementation checks for @javax.validation.Valid
,
Spring's Validated
,
and custom annotations whose name starts with "Valid".
binder
- the DataBinder to be usedmethodParam
- the method parameterMethodArgumentNotValidException
- in case of a binding error which
is meant to be fatal (i.e. without a declared Errors
parameter)private boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter methodParam)
binder
- the data binder used to perform data bindingmethodParam
- the method argumenttrue
if the next method argument is not of type Errors